package com.yangcheng.service.impl;

import com.yangcheng.dao.AuthorityMapper;
import com.yangcheng.model.domain.Authority;
import com.yangcheng.service.IArticleService;
import com.yangcheng.service.IAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("AuthorityService")
public class AuthorityServiceImpl  implements IAuthorityService {


        @Autowired
        AuthorityMapper authorityMapper;
        @Autowired
        RedisTemplate redisTemplate;
        @Override
        public List<Authority> getCustomerAuthority(String username) {
            Object o = redisTemplate.opsForValue().get("authority_" + username);
            if(o!=null)
            {
                return (List<Authority>)o;
            }
            List<Authority> authorities = authorityMapper.authoritiesByUsernameQuery(username);
            if(authorities.size()>0)
            {
                redisTemplate.opsForValue().set("authority_" + username,authorities);
            }

            return authorities;
        }

}
